package com.gzdh.dishrecognition.ui.adapter.report;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.gzdh.dishrecognition.R;
import com.gzdh.dishrecognition.model.LcReportDto;

import java.util.ArrayList;
import java.util.List;

public class LcReportAdapter extends RecyclerView.Adapter<LcReportAdapter.ViewHolder> {


    private Context mcontext;
    private List<LcReportDto> lcReportDtoList;

    private int paddingSize;

    public List<LcReportDto> getLcReportDtoList() {
        return lcReportDtoList;
    }

    public void setLcReportDtoList(List<LcReportDto> lcReportDtoList) {
        this.lcReportDtoList = lcReportDtoList;
        notifyDataSetChanged();

    }

    public LcReportAdapter(Context context) {
        mcontext = context;
        this.lcReportDtoList = new ArrayList<>();
        this.paddingSize = -1;
    }

    public LcReportAdapter(Context context, int paddingSize) {
        mcontext = context;
        this.lcReportDtoList = new ArrayList<>();
        this.paddingSize = paddingSize;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_lc, parent, false);
        return new ViewHolder(itemView, paddingSize);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.hNameTv.setText(String.valueOf(lcReportDtoList.get(position).gethName()).trim());
        holder.slTv.setText(lcReportDtoList.get(position).getSl());
        holder.jeTv.setText(lcReportDtoList.get(position).getJe());
        holder.lcTimeTv.setText(lcReportDtoList.get(position).getLC());
        holder.status.setText("1".equals(lcReportDtoList.get(position).getStatus()) ? "已领餐" : "未领餐");
        holder.orderTv.setText(lcReportDtoList.get(position).getZFSerialNumber());
    }

    @Override
    public int getItemCount() {
        return lcReportDtoList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        LinearLayout mainLinear;
        TextView orderTv;
        TextView hNameTv;
        TextView slTv;
        TextView jeTv;
        TextView lcTimeTv;
        TextView status;

        ViewHolder(View item, int paddingSize) {
            super(item);
            mainLinear = item.findViewById(R.id.mainLinear);
            if(paddingSize != -1) {
                mainLinear.setPadding(0, paddingSize, 0, paddingSize);
            }
            orderTv = item.findViewById(R.id.orderTv);

            hNameTv = item.findViewById(R.id.hNameTv);
            slTv = item.findViewById(R.id.slTv);
            jeTv = item.findViewById(R.id.jeTv);
            lcTimeTv = item.findViewById(R.id.lcTimeTv);
            status = item.findViewById(R.id.statusTv);
        }

    }

}
